export function localGet(key) {
  const value = window.localStorage.getItem(key);
  try {
    return JSON.parse(window.localStorage.getItem(key));
  } catch (error) {
    return value;
  }
}

export function localSet(key, value) {
  window.localStorage.setItem(key, JSON.stringify(value));
}

export function localRemove(key) {
  window.localStorage.removeItem(key);
}

//设置cookie
export function cookieSet(c_name, value, expire) {
  var date = new Date();
  date.setSeconds(date.getSeconds() + expire);
  document.cookie =
    c_name + "=" + escape(value) + "; expires=" + date.toGMTString();
  console.log(`看看Cookie吧`, document.cookie);
}
//获取cookie
export function cookieGet(c_name) {
  if (document.cookie.length > 0) {
    let c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1;
      let c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return "";
}
/*删除cookie*/
export function cookieRemove(c_name) {
  setCookie(c_name, "", -1);
}

// 判断内容是否含有表情字符，现有数据库不支持。
export function hasEmoji(str = "") {
  const reg =
    /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
  return str.match(reg) && str.match(reg).length;
}

// 单张图片上传
export const uploadImgServer = "";
// 多张图片上传
export const uploadImgsServer = "";

export const pathMap = {
  login: "登录",
  dashboard: "大盘数据",
  add: "添加商品",
  swiper: "轮播图配置",
  hot: "热销商品配置",
  new: "新品上线配置",
  recommend: "为你推荐配置",
  category: "分类管理",
  level2: "分类二级管理",
  level3: "分类三级管理",
  good: "商品管理",
  guest: "会员管理",
  order: "订单管理",
  order_detail: "订单详情",
  account: "修改账户",
};
